SetCompressor /SOLID /FINAL lzma

!include "..\version.nsh"
!define NAME "VimKick"
Name "${NAME}"

; The file to write
OutFile "vimkick-${VIM_KICK_VERSION}.exe"

InstallDir $PROGRAMFILES\${NAME}

; Registry key to check for directory (so if you install again, it will 
; overwrite the old one automatically)
InstallDirRegKey HKLM "Software\${NAME}" "Path"

;--------------------------------

; Pages

Page components
Page directory
Page instfiles

UninstPage uninstConfirm
UninstPage instfiles

;--------------------------------

; The stuff to install
Section "${NAME} (required)"

  SectionIn RO
  
  ; Set output path to the installation directory.
  SetOutPath $INSTDIR
  
  
  ; Write the installation path into the registry
  WriteRegStr HKLM "Software\${NAME}" "Path" "$INSTDIR"
  WriteRegStr HKLM "Software\${NAME}" "Version" "${VIM_KICK_VERSION}"
  
  ; Write the uninstall keys for Windows
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}" "DisplayName" "${NAME}"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}" "UninstallString" '"$INSTDIR\uninstall.exe"'
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}" "NoRepair" 1
  WriteUninstaller "uninstall.exe"

  ; Put file there
  File "..\release\vimkick.exe"
  File "..\ctags.exe"
  File /oname=CHANGELOG.txt "..\CHANGELOG"
  File /oname=LICENSE.txt "..\LICENSE"
  
SectionEnd

; Optional section (can be disabled by the user)
Section "Start Menu Shortcuts"

  CreateDirectory "$SMPROGRAMS\${NAME}"
  CreateShortCut "$SMPROGRAMS\${NAME}\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
  CreateShortCut "$SMPROGRAMS\${NAME}\${NAME}.lnk" "$INSTDIR\vimkick.exe" "" "$INSTDIR\vimkick.exe" 0
  CreateShortCut "$SMPROGRAMS\${NAME}\Changelog.lnk" "$INSTDIR\CHANGELOG.txt" 
  CreateShortCut "$SMPROGRAMS\${NAME}\License.lnk" "$INSTDIR\LICENSE.txt" 
  
SectionEnd

;--------------------------------

; Uninstaller

Section "Uninstall"
  
  ; Remove registry keys
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}"
  DeleteRegKey HKLM SOFTWARE\${NAME}

  ; Remove files and uninstaller
  Delete $INSTDIR\vimkick.exe
  Delete $INSTDIR\ctags.exe
  Delete $INSTDIR\CHANGELOG.txt
  Delete $INSTDIR\LICENSE.txt
  Delete $INSTDIR\uninstall.exe

  ; Remove shortcuts, if any
  Delete "$SMPROGRAMS\${NAME}\*.*"

  ; Remove directories used
  RMDir "$SMPROGRAMS\${NAME}"
  RMDir "$INSTDIR"

SectionEnd
